package com.guinea.core.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import modules.system.entity.User;

import org.apache.struts.taglib.TagUtils;

import com.guinea.core.SpringContextHolder;
import com.guinea.core.utils.ReflectionUtils;
import com.guinea.core.utils.StringUtils;

import ex.system.service.UserServiceEx;

public class UserTag extends CommonTag {
	public int doEndTag() throws JspException {
		String strAttr = "";
		Long id = (Long) TagUtils.getInstance().lookup(pageContext, name,
				property, null);
		UserServiceEx userServiceEx = (UserServiceEx) SpringContextHolder
				.getBean("userServiceEx");
		if (id != null) {
			User user = userServiceEx.getUser(id);
			if (user != null) {
				if (StringUtils.isEmpty(attr)) {
					strAttr = user.getOtherName();
				} else {
					Object x = ReflectionUtils.getFieldValue(user, attr);
					if (x != null)
						strAttr = x.toString();
				}
			}
		}
		try {
			pageContext.getOut().print(strAttr);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return super.doEndTag();
	}

}
